//
// Created by xili on 2024/8/22 10:04.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector<int> decrypt(vector<int> &code, int k) {
        int n = code.size();
        vector<int> ans(n, 0);
        if (0 == k) {
            return ans;
        }
        int index = k > 0 ? 1 : n + k + 1;
        int size = abs(k);
        int sum = 0;
        for (int i = index; i < index + k; i++) {
            sum += code[i % n];
        }
        for (int i = 0; i < n; i++) {
            ans[i] = sum;
            sum -= code[(index + i) % n];
            sum += code[(index + size + i) % n];
        }
        return ans;
    }
};